package com.example.dairenkun.neufoodshop.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dairenkun.neufoodshop.R;
import com.example.dairenkun.neufoodshop.adapter.FoodCommentAdapter;
import com.example.dairenkun.neufoodshop.adapter.FoodListAdapter;
import com.example.dairenkun.neufoodshop.bean.Food;
import com.example.dairenkun.neufoodshop.bean.Order;
import com.example.dairenkun.neufoodshop.model.FoodModel;
import com.example.dairenkun.neufoodshop.service.FoodService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class FoodCommentActivity extends AppCompatActivity {
  private TextView shopname;
    private TextView foodname;
    private TextView foodprice;
    private TextView foodmoney;
    private ImageView foodimage;
    private RecyclerView recyclerView;
    int foodid;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_food_comment);
        initViews();
        getData();
        //获取数据
        FoodModel foodModel=new FoodModel();
        Call call=foodModel.FoodDetail(foodid);
        call.enqueue(new Callback<Food>() {
            @Override
            public void onResponse(Call<Food> call, retrofit2.Response<Food> response)
            {
                Food food=response.body();
                foodname.setText(food.getFoodname());
                // Picasso.with(FoodCommentActivity.this).load(food.getPic()).into(foodimage);
                foodmoney.setText(food.getPrice());
               // shopname.setText();
                //图片加载  店铺名字

            }
            @Override
            public void onFailure(Call<Food> call, Throwable t) {

            }
        });


    }
    private void getData() {
        Intent intent =getIntent();
        int foodid=Integer.valueOf(intent.getStringExtra("food_id"));
        //获取网上的数据/
       /* Retrofit retrofit=new Retrofit.Builder()
                .baseUrl("http://60.205.189.39/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        FoodService testService=retrofit.create(FoodService.class);
        Call<List<Order>> call=testService.getFoodComment(foodid);*/
        FoodModel foodModel=new FoodModel();
        Call<List<Order>> call=foodModel.FoodCommentList(foodid);
        call.enqueue(new Callback<List<Order>>() {
            @Override
            public void onResponse(Call<List<Order>> call, retrofit2.Response<List<Order>> response)
            {
                List<Order> food=response.body();
                recyclerView.setAdapter(new FoodCommentAdapter(FoodCommentActivity.this,food));
            }
            @Override
            public void onFailure(Call<List<Order>> call, Throwable t) {

            }
        });
    }
    public void initViews(){
        shopname=(TextView)findViewById(R.id.foodcommnet_shopname);
        foodname=(TextView)findViewById(R.id.foodcomment_foodname);
        foodprice=(TextView)findViewById(R.id.foodcomment_price);
        foodmoney=(TextView)findViewById(R.id.foodcomment_money);
        foodimage=(ImageView)findViewById(R.id.img_foodcomment);
        recyclerView=(RecyclerView)findViewById(R.id.recycler_id_foodComment);
        recyclerView.setLayoutManager(new LinearLayoutManager(FoodCommentActivity.this));
    }
}
